package com.jdjt.dams.goods;

import com.base.common.utils.StringUtil;
import com.jfinal.plugin.activerecord.Page;

public class GoodsService {

	
	public static final String findGoodsList = null;

	//查询列表
	public Page<GoodsModel> findGoodsList(int pageNumber,int pageSize,GoodsModel goodsModel){
		Page<GoodsModel> goods = GoodsModel.dao.paginate(pageNumber, pageSize, "select * ", "from cshm_goods");
		return goods;
	}
	
	//查询列表
		public Page<GoodsModel> findByGoodsModelList(int pageNumber,int pageSize,GoodsModel goodsModel){
			//如果设置为true时就是代表为已经设置where了
			boolean bool=false;
			String sql="from cshm_goods";
			if(!StringUtil.isNull(goodsModel)){				
				if(!StringUtil.isNull(goodsModel.get("goods_name"))){
					sql=sql+" where goods_name="+goodsModel.get("goods_name");
					bool=true;
				}
				if(!StringUtil.isNull(goodsModel.get("type"))){
					if(bool){
						sql=sql+" and type="+goodsModel.get("type");
					}else{
						sql=sql+" where type="+goodsModel.get("type");
						bool=true;
					}
					
				}
				if(!StringUtil.isNull(goodsModel.get("if_show"))){
					if(bool){
						sql=sql+" and if_show="+goodsModel.get("if_show");
					}else{
						sql=sql+" where if_show="+goodsModel.get("if_show");
					}
					
				}
			}
			
			Page<GoodsModel> goods = GoodsModel.dao.paginate(pageNumber, pageSize, "select * ", sql);
			return goods;
		}
	
	
	//查询列表
	public GoodsModel findGoodsbyId(String id){
		GoodsModel goods = GoodsModel.dao.findById(id);
		return goods;
	}
	
	public boolean insertGoods(GoodsModel goodsModel){
		boolean bool=goodsModel.save();
		return bool;
	}
	
	//删除商品
	public boolean deleteGoods(String id){
		boolean bool=GoodsModel.dao.deleteById(id);
		return bool;
	}
	
	public boolean update(GoodsModel goodsModel){
		boolean bool=goodsModel.update();
		return bool;
	}
	
}
